package com.zhu.pre.controller;

import com.sanploy.common.vo.BaseException;
import com.zhu.pre.service.MGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by zhu yingzhi on 2017/9/21.
 * @author yingzhi zhu
 * 手机商品请求路由类
 */
@RestController
@RequestMapping("/m/goods")
public class MGoodsController {

    @Autowired
    private MGoodsService mGoodsService;

    /**
     * 查看所有通过时间排序
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/all")
    public Object getAllPage(@RequestParam int currentPage, @RequestParam int pageSize){
        return mGoodsService.selectAllByPage(currentPage, pageSize);
    }

    /**
     * 查看分类下的所有 通过时间排序
     * @param currentPage
     * @param pageSize
     * @param cat_id
     * @return
     */
    @GetMapping("/cat")
    public Object getCatIdPage(@RequestParam int currentPage, @RequestParam int pageSize,@RequestParam Long cat_id){
        return mGoodsService.selectByCatIdPage(currentPage, pageSize,cat_id);
    }

    /**
     * 查找所有热们商品
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/hot")
    public Object getHotPage(@RequestParam int currentPage, @RequestParam int pageSize){
        return mGoodsService.selectByHotPage(currentPage, pageSize);
    }

    /**
     * 查找所有精品
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/best")
    public Object getBestPage(@RequestParam int currentPage, @RequestParam int pageSize){
        return mGoodsService.selectByBestPage(currentPage, pageSize);
    }


    /**
     * 根据商品Id查询商品
     * @param id 商品Id
     * @return
     * @throws BaseException
     */
    @GetMapping("/{id}")
    public Object getOneGoods(@PathVariable Long id) throws BaseException {
        return mGoodsService.getGoodsById(id);
    }
}
